package com.bosch.in.jfree.chart;

import java.util.ArrayList;
import java.util.List;
import org.jfree.chart.imagemap.ToolTipTagFragmentGenerator;
import org.jfree.data.category.CategoryDataset;

import com.bosch.in.rtp1.ept.model.dto.BoxPlotFactor;

public class BoxPlotChart extends AbstractBoxPlotChart{
	private List<BoxPlotFactor> factors ;
	private List<String> toolTips =new ArrayList<String>();
//	private String totalItemString = "Total Items";
	public BoxPlotChart(List<BoxPlotFactor> factors, String... title)
	{
		this.factors = factors;
		if (title.length>0)
		{
			this.setTitle(title[0]);
		}
			
	}
	
	@Override
	public CategoryDataset createDatasetLeftAxis() {
	        int categoryCount = this.factors.size();
	        BoxPlotChartDataSetCustomize dataset = new BoxPlotChartDataSetCustomize();
	            for (int i = 0; i < categoryCount; i++) 
	            {
	                List<Number> list = new ArrayList<Number>();
	                BoxPlotFactor factor = factors.get(i);
			        list.add(factor.getSigmaTop());
			        list.add(factor.getSigmaMiddle1());
			        list.add(factor.getMedian());
			        list.add(factor.getSigmaMiddle2());
			        list.add(factor.getSigmaBottom());
			        list.add(factor.getTotalItem());
	                dataset.add(list, "", factor.getxLineValue());
	                if (factor.getSigmaTop() != null)
	                {
	                	toolTips.add(factor.getxLineValue());
	                }
	            }
			return dataset;
	}
	
	@Override
	public ToolTipTagFragmentGenerator getToolTipTagFragmentGenerator() {
		String captionTemplate = "<div align='center' style='white-space:nowrap; color: #5C9200'>{2}</div>" + 
		  "<div>{1}</div>";
		return new DefaultToolTipTagFragmentGenerator(toolTips,captionTemplate);
	};
	
	@Override
	public boolean writeImageMap() {
		return false;
	}

}
